﻿using System;
using System.ComponentModel;
using System.Diagnostics;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Collections.Generic;

namespace KOF.ViewModels
{
    public class ItemViewModel : INotifyPropertyChanged
    {
        private string _id;
        public string id
        {
            get
            {
                return _id;
            }
            set
            {
                _id = value;
                NotifyPropertyChanged("id");
            }
        }

        private string _title;
        public string title
        {
            get
            {
                return _title;
            }
            set
            {
                _title = value;
                NotifyPropertyChanged("title");
            }
        }

        private string _style;
        public string style
        {
            get
            {
                return _style;
            }
            set
            {
                _style = value;
                NotifyPropertyChanged("style");
            }
        }

        private string _thumb_ipad_master_image;
        public string thumb_ipad_master_image
        {
            get
            {
                return _thumb_ipad_master_image;
            }
            set
            {
                _thumb_ipad_master_image = value;
                NotifyPropertyChanged("thumb_ipad_master_image");
            }
        }

        private string _thumb_iphone_master_image;
        public string thumb_iphone_master_image
        {
            get
            {
                return _thumb_iphone_master_image;
            }
            set
            {
                _thumb_iphone_master_image = value;
                NotifyPropertyChanged("thumb_iphone_master_image");
            }
        }

        private string _master_ipad_image;
        public string master_ipad_image
        {
            get
            {
                return _master_ipad_image;
            }
            set
            {
                _master_ipad_image = value;
                NotifyPropertyChanged("master_ipad_image");
            }
        }

        private string _master_iphone_image;
        public string master_iphone_image
        {
            get
            {
                return _master_iphone_image;
            }
            set
            {
                _master_iphone_image = value;
                NotifyPropertyChanged("master_iphone_image");
            }
        }

        private string _master_image;
        public string master_image
        {
            get
            {
                return _master_image;
            }
            set
            {
                _master_image = value;
                NotifyPropertyChanged("master_image");
            }
        }

        private string _description;
        public string description
        {
            get
            {
                return _description;
            }
            set
            {
                _description = value;
                NotifyPropertyChanged("description");
            }
        }


        private DateTime _event_date;
        public DateTime event_date
        {
            get
            {
                return _event_date;
            }
            set
            {
                if (value != _event_date)
                {
                    _event_date = value;
                    NotifyPropertyChanged("event_date");
                }
            }
        }

        private string _price;
        public string price
        {
            get
            {
                return _price;
            }
            set
            {
                _price = value;
                NotifyPropertyChanged("price");
            }
        }

        private string _kof_link;
        public string kof_link
        {
            get
            {
                return _kof_link;
            }
            set
            {
                _kof_link = value;
                NotifyPropertyChanged("kof_link");
            }
        }

        private string _kxf_link;
        public string kxf_link
        {
            get
            {
                return _kxf_link;
            }
            set
            {
                _kxf_link = value;
                NotifyPropertyChanged("kxf_link");
            }
        }

        private List<object> _images;
        public List<object> images
        {
            get
            {
                return _images;
            }
            set
            {
                _images = value;
                NotifyPropertyChanged("images");
            }
        }

        private List<object> _ipad_images;
        public List<object> ipad_images
        {
            get
            {
                return _ipad_images;
            }
            set
            {
                _ipad_images = value;
                NotifyPropertyChanged("ipad_images");
            }
        }

        private List<object> _iphone_images;
        public List<object> iphone_images
        {
            get
            {
                return _iphone_images;
            }
            set
            {
                _iphone_images = value;
                NotifyPropertyChanged("iphone_images");
            }
        }

        private string _created_on;
        public string created_on
        {
            get
            {
                return _created_on;
            }
            set
            {
                _created_on = value;
                NotifyPropertyChanged("created_on");
            }
        }

        private string _updated_on;
        public string updated_on
        {
            get
            {
                return _updated_on;
            }
            set
            {
                _updated_on = value;
                NotifyPropertyChanged("updated_on");
            }
        }

        private bool _IsDownloading;
        public bool IsDownloading
        {
            get
            {
                return _IsDownloading;
            }
            set
            {
                _IsDownloading = value;
                NotifyPropertyChanged("IsDownloading");
            }
        }

        public String FormattedDateTime
        {
            get
            {
                return event_date == DateTime.MinValue ? String.Empty : GetFormattedDate(_event_date);
            }
        }

        public event PropertyChangedEventHandler PropertyChanged;
        private void NotifyPropertyChanged(String propertyName)
        {
            PropertyChangedEventHandler handler = PropertyChanged;
            if (null != handler)
            {
                handler(this, new PropertyChangedEventArgs(propertyName));
            }
        }

        public static String GetFormattedDate(DateTime time)
        {
            var time1 = time.ToShortDateString();
            var time2 = DateTime.Now.ToLocalTime().ToShortDateString();

            if (time1 == time2)
                return time.ToShortTimeString();

            return String.Format("{0} {1}", time.ToShortDateString(), time.ToShortTimeString());
        }
    }
}
